package com.wv.api.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.TimeInterval;
import com.wv.api.service.ITestService;
import com.wv.common.result.Result;
import com.wv.model.system.Test;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

@Service
public class TestServiceImpl implements ITestService {

    @Override
    @Transactional(rollbackFor = Exception.class) // 添加事务，异常则回滚所有导入
    public Result createFunctionDatasourceAndSwMbqcdss(Test createReqVO, MultipartFile file) throws IOException, ExecutionException, InterruptedException {
//        //新增数据源，或者id
//        FunctionDatasourceDO functionDatasource = FunctionDatasourceConvert.INSTANCE.convert(createReqVO);
//        functionDatasourceMapper.insert(functionDatasource);
//        Long id = functionDatasource.getId();
//        //获取当前登录用户
//        Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
//        //开始计时
//        TimeInterval timer = DateUtil.timer();
//        //DataExcelImportRespVO respVO = readExcelAndSave(DataSwMbqcdssImportExcelVO.class, file, data -> DataSwMbqcdssConvert.INSTANCE.convert(data).setDsId(id), dataSwMbqcdssInsertMapper::saveBatch);
//        DataExcelImportRespVO respVO = readExcelAndSaveAsync(DataSwMbqcdssImportExcelVO.class,
//                file,
//                data -> {
//                    DataSwMbqcdssDO newDo = DataSwMbqcdssConvert.INSTANCE.convert(data).setDsId(id);
//                    //数据预处理，因为目前的批处理方法不会再自动填充数据，所以这里手动填充
//                    newDo.setCreator(String.valueOf(loginUserId));
//                    newDo.setUpdater(String.valueOf(loginUserId));
//                    newDo.setDeleted(false);
//                    return newDo;
//                },
//                dataSwMbqcdssBatchInsertMapper::insertBatchSomeColumn);
//        //结束计时
//        long interval = timer.interval();
//        log.info("导入数据共花费：{}s", interval / 1000);
//        respVO.setTime(interval);
//        // 存储文件
//        saveDsFile(id,file);
//        return respVO;
        return null;
    }
}
